using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SystemFramework.Util;

namespace TF.Access
{
    public partial class TF_View
    {
        /// <summary>
        /// Selects all records from the TF_View table.
        /// </summary>
        public static List<TF_View> SelectByCityId(int cityId,int pageSize, int pageIndex)
        {
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_ViewSelectByCityId", cityId, pageSize, pageIndex))
            {
                List<TF_View> tF_ViewList = new List<TF_View>();
                while (dataReader.Read())
                {
                    TF_View tF_View = MakeTF_View(dataReader);
                    tF_ViewList.Add(tF_View);
                }
                return tF_ViewList;
            }
        }

        public static List<TF_View> SelectViewByKeyword(string keywords, int pageSize, int pageIndex)
        {
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_SelectViewByKeyword", keywords, pageSize, pageIndex))
            {
                List<TF_View> tF_ViewList = new List<TF_View>();
                while (dataReader.Read())
                {
                    TF_View tF_View = new TF_View();
                    if (dataReader.IsDBNull(0) == false)
                    {
                        tF_View.ID = dataReader.GetInt32(0);
                    }
                    if (dataReader.IsDBNull(1) == false)
                    {
                        tF_View.URL = dataReader.GetString(1);
                    }
                    if (dataReader.IsDBNull(2) == false)
                    {
                        tF_View.Name = dataReader.GetString(2);
                    }
                    if (dataReader.IsDBNull(3) == false)
                    {
                        tF_View.detail = dataReader.GetString(3);
                    }
                    tF_ViewList.Add(tF_View);
                }
                return tF_ViewList;
            }
        }

        public static int SelectViewByKeywordCount(string keywords)
        {
            return ConvertHelper.GetInt(SqlClientUtility.ExecuteScalar("TF_SelectViewByKeywordCount", keywords),0);
        }

        public static int SelectByCityIdCount(int cityId)
        {
            object ret = SqlClientUtility.ExecuteScalar("TF_ViewSelectByCityIdCount", cityId);
            return int.Parse(ret.ToString());
        }

        public static List<CityView> SelectAllCityView()
        {
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_SelectAllCityView"))
            {
                List<CityView> citiViewList = new List<CityView>();
                while (dataReader.Read())
                {
                    CityView cityView = new CityView();
                    cityView.CityID = dataReader.IsDBNull(0)?0:dataReader.GetInt32(0);
                    cityView.ID = dataReader.IsDBNull(1) ? 0 : dataReader.GetInt32(1);
                    cityView.CityViewString = dataReader.IsDBNull(2) ? string.Empty : dataReader.GetString(2);
                    citiViewList.Add(cityView);
                }
                return citiViewList;
            }
        }
    }

    public partial class CityView
    {
        int iD;
        int cityID;
        string cityView;
        public int ID
        {
            get { return iD; }
            set { iD = value; }
        }

        public int CityID
        {
            get { return cityID; }
            set { cityID = value; }
        }
        public string CityViewString
        {
            get
            {
                return cityView;
            }
            set
            {
                cityView = value;
            }
        }
    }
}
